import { createAsyncThunk } from '@reduxjs/toolkit'
import { getMenuRequest, getUserInfoRequest, getStudentList, getAdminList } from '@/util/request'
import { UserInfo, MenuData, Page } from '@/util/interface'
import { GetAdminList } from '@/util/interface'

// createAsyncThunk 函数用于创建一个异步 thunk，它接受一个 action 类型前缀和一个异步函数作为参数。
// 获取菜单
export const get_menu_async = createAsyncThunk<MenuData[]>('get/user_menu', async (action, state) => {
  return await getMenuRequest()
})

// 获取用户信息
export const get_user_info_async = createAsyncThunk<UserInfo>('get/user_info', async (action, state) => {
  return await getUserInfoRequest()
})

// 获取学生列表
export const get_student_list_data_async = createAsyncThunk<any, any>('get/student_list_data', async (action, state) => {
  return await getStudentList(action)
})

// 获取管理员列表
export const get_admin_list_async = createAsyncThunk<Page<UserInfo[]>, GetAdminList>('get/admin_list', async (action, state) => {
  return await getAdminList(action)
})

